package com.ruoyi.web.controller.system;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WorkArea;
import com.ruoyi.system.service.IWorkAreaService;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/system/area")
public class WorkAreaController extends BaseController
{
    @Autowired
    private IWorkAreaService workAreaService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WorkArea workArea)
    {
        startPage();
        List<WorkArea> list = workAreaService.selectWorkAreaList(workArea);
        return getDataTable(list);
    }
    
    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/listTree")
    public AjaxResult listTree(WorkArea workArea)
    {
       
        List<WorkArea> list = workAreaService.getWorkAreaTreeList(workArea);
        return success(list);
    }
    
    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:export')")
    @Log(title = "地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkArea workArea)
    {
        List<WorkArea> list = workAreaService.selectWorkAreaList(workArea);
        ExcelUtil<WorkArea> util = new ExcelUtil<WorkArea>(WorkArea.class);
        util.exportExcel(response, list, "地区数据");
    }

    /**
     * 获取地区详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workAreaService.selectWorkAreaById(id));
    }

    /**
     * 新增地区
     */
    @PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "地区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkArea workArea)
    {
        return toAjax(workAreaService.insertWorkArea(workArea));
    }

    /**
     * 修改地区
     */
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "地区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkArea workArea)
    {
        return toAjax(workAreaService.updateWorkArea(workArea));
    }

    /**
     * 删除地区
     */
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "地区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workAreaService.deleteWorkAreaByIds(ids));
    }
}
